{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #加密运算"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #bit-manipulation #math"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #位运算 #数学"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: encryptionCalculate"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #加密运算"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>计算机安全专家正在开发一款高度安全的加密通信软件，需要在进行数据传输时对数据进行加密和解密操作。假定 <code>dataA</code> 和 <code>dataB</code> 分别为随机抽样的两次通信的数据量：</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>正数为发送量</li>\n",
    "\t<li>负数为接受量</li>\n",
    "\t<li>0 为数据遗失</li>\n",
    "</ul>\n",
    "\n",
    "<p>请不使用四则运算符的情况下实现一个函数计算两次通信的数据量之和（三种情况均需被统计），以确保在数据传输过程中的高安全性和保密性。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1:</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>dataA = 5, dataB = -1\n",
    "<strong>输出：</strong>4\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>dataA</code>&nbsp;和 <code>dataB</code>&nbsp;均可能是负数或 0</li>\n",
    "\t<li>结果不会溢出 32 位整数</li>\n",
    "</ul>\n",
    "\n",
    "<p>&nbsp;</p>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof](https://leetcode.cn/problems/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof](https://leetcode.cn/problems/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        return dataA + dataB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        if dataA == 0:\n",
    "            return dataB\n",
    "        elif dataB == 0:\n",
    "            return dataA\n",
    "        else:\n",
    "            return sum([dataA,dataB])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        x = 0xffffffff\n",
    "        dataA, dataB = dataA & x, dataB & x\n",
    "        while dataB != 0:\n",
    "            dataA, dataB = (dataA ^ dataB), (dataA & dataB) << 1&x\n",
    "        return dataA if dataA <= 0x7fffffff else ~(dataA ^ x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        return dataA + dataB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        # 位运算 &进位和 ^无进位和\n",
    "        x = 0xffffffff\n",
    "        dataA, dataB = dataA & x, dataB & x\n",
    "        while dataB != 0:\n",
    "            dataA, dataB = (dataA ^ dataB), (dataA & dataB) << 1 & x\n",
    "        return dataA if dataA <= 0x7fffffff else ~(dataA ^ x)\n",
    "\n",
    "        # 不符合题目要求\n",
    "        return dataA+dataB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        x = 0xffffffff\n",
    "        dataA, dataB = dataA & x, dataB & x\n",
    "        while dataB != 0:\n",
    "            dataA, dataB = (dataA ^ dataB), (dataA & dataB) << 1 & x\n",
    "        return dataA if dataA <= 0x7fffffff else ~(dataA ^ x)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        add_ = dataB\n",
    "        sum_ = dataA\n",
    "        while add_:\n",
    "            tmp = sum_ ^ add_\n",
    "            add_ = (sum_ & add_) << 1\n",
    "            sum_ = tmp & 0xFFFFFFFF\n",
    "        if sum_ >> 31 == 0:\n",
    "            return sum_\n",
    "        else:   # 处理负数问题，最小的情况\n",
    "            return sum_ - 4294967296"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        return dataA + dataB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        return dataA+dataB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        x = 0xffffffff\n",
    "        dataA,dataB=dataA&x,dataB&x\n",
    "        while dataB !=0:\n",
    "            dataA,dataB = dataA^dataB,((dataA&dataB)<<1)&x\n",
    "        if dataA <=0x7fffffff:\n",
    "            return dataA\n",
    "        else:\n",
    "            return ~(dataA^x)\n",
    "\n",
    "        # x=0xffffffff\n",
    "        # dataA &= x\n",
    "        # dataB &= x\n",
    "        # while dataB!=0: # 直到进位为0\n",
    "        #     temp = ((dataA&dataB)<<1)&x  # 进位：与运算 + 左移一位\n",
    "        #     dataA^=dataB   # 本位：异或运算\n",
    "        #     dataB=temp \n",
    "        # if dataA <= 0x7fffffff: #0x7fffffff 是最大的正数的补码。\n",
    "        # # 当你尝试将 0x7fffffff 加 1 时，会发生溢出，结果将变为负数，即 -2147483648\n",
    "        #     return dataA\n",
    "        # else:\n",
    "        #     return ~(dataA^x)  #计算整数 a 的相反数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        x = 0xffffffff\n",
    "        a,b = x&dataA,x&dataB\n",
    "        while b!=0:\n",
    "            a,b = a^b,((a&b)<<1)&x\n",
    "        return a if a <=0x7fffffff else ~(a^x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        return dataA + dataB\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        x = 0xffffffff\n",
    "        dataA, dataB = dataA & x, dataB & x\n",
    "        while dataB != 0:\n",
    "            dataA, dataB = (dataA ^ dataB), (dataA & dataB) << 1 & x\n",
    "        return dataA if dataA <= 0x7fffffff else ~(dataA ^ x)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        return dataA + dataB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        dataA &= 0xffffffff\n",
    "        dataB &= 0xffffffff\n",
    "        while dataB!=0:\n",
    "            temp = ((dataA&dataB)<<1)&0xffffffff\n",
    "            dataA^=dataB\n",
    "            dataB=temp\n",
    "        if dataA <= 0x7fffffff:\n",
    "            return dataA\n",
    "        else:\n",
    "            return ~(dataA^0xffffffff)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        return dataA + dataB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        return dataA+dataB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        x = 0xffffffff\n",
    "        dataA, dataB = dataA & x, dataB & x\n",
    "        while dataB != 0:\n",
    "            dataA, dataB = (dataA ^ dataB), (dataA & dataB) << 1 & x\n",
    "        return dataA if dataA <= 0x7fffffff else ~(dataA ^ x)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        x = 0xffffffff\n",
    "        dataA, dataB = dataA & x, dataB & x\n",
    "        while dataB != 0:\n",
    "            dataA, dataB = (dataA ^ dataB), (dataA & dataB) << 1 & x\n",
    "        return dataA if dataA <= 0x7fffffff else ~(dataA ^ x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        x = 0xffffffff\n",
    "        dataA, dataB = dataA & x, dataB & x\n",
    "        while dataB != 0:\n",
    "            dataA, dataB = (dataA ^ dataB), (dataA & dataB) << 1 & x\n",
    "        return dataA if dataA <= 0x7fffffff else ~(dataA ^ x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        x = 0xffffffff\n",
    "        dataA, dataB = dataA & x, dataB & x\n",
    "        while dataB != 0:\n",
    "            dataA, dataB = (dataA ^ dataB), (dataA & dataB) << 1 & x\n",
    "        return dataA if dataA <= 0x7fffffff else ~(dataA ^ x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        x = 0xffffffff\n",
    "        a, b = dataA & x, dataB & x\n",
    "        while b != 0:\n",
    "            a, b = (a ^ b), (a & b) << 1 & x\n",
    "        return a if a <= 0x7fffffff else ~(a ^ x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        return dataA+dataB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        dataA &= 0xffffffff\n",
    "        dataB &= 0xffffffff\n",
    "        while dataB != 0:\n",
    "            carry = ((dataA & dataB) << 1) & 0xffffffff\n",
    "            dataA ^= dataB\n",
    "            dataB = carry\n",
    "        return dataA if dataA < 0x80000000 else ~(dataA^0xffffffff)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        x = 0xffffffff\n",
    "        dataA, dataB = dataA & x, dataB & x\n",
    "        while dataB != 0:\n",
    "            dataA, dataB = (dataA ^ dataB), (dataA & dataB) << 1 & x\n",
    "        return dataA if dataA <= 0x7fffffff else ~(dataA ^ x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        return dataA + dataB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        x = 0xffffffff\n",
    "        dataA, dataB = dataA & x, dataB & x\n",
    "        while dataB != 0:\n",
    "            dataA, dataB = (dataA ^ dataB), (dataA & dataB) << 1 & x\n",
    "        return dataA if dataA <= 0x7fffffff else ~(dataA ^ x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        x = 0xffffffff\n",
    "        dataA, dataB = dataA & x, dataB & x\n",
    "        while dataB != 0:\n",
    "            dataA, dataB = (dataA ^ dataB), (dataA & dataB) << 1 & x\n",
    "        return dataA if dataA <= 0x7fffffff else ~(dataA ^ x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        return dataA+dataB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        to_add = 0\n",
    "        ans = 0\n",
    "        for i in range(32):\n",
    "            c1 = (dataA>>i)&1\n",
    "            c2 = (dataB>>i)&1\n",
    "\n",
    "            if to_add and c1 and c2:\n",
    "                ans = ans | (1<<i)\n",
    "                to_add = 1\n",
    "            elif (to_add and c1) or (to_add and c2) or (c1 and c2):\n",
    "                to_add = 1\n",
    "            elif to_add or c1 or c2:\n",
    "                ans = ans | (1<<i)\n",
    "                to_add = 0\n",
    "            else:\n",
    "                to_add = 0\n",
    "        \n",
    "        if (ans>>31)&1:\n",
    "            ans = ~((ans ^ 0xFFFFFFFF) & 0xFFFFFFFF)\n",
    "        else:\n",
    "            ans = ans & 0xFFFFFFFF\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        x = 0xffffffff\n",
    "        dataA, dataB = dataA & x, dataB & x\n",
    "        while dataB != 0:\n",
    "            dataA, dataB = dataA ^ dataB, ((dataA & dataB) << 1) & x\n",
    "        return dataA if dataA <= 0x7fffffff else ~(dataA ^ x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        return dataA + dataB\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        return dataA + dataB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        x = 0xffffffff\n",
    "        dataA, dataB = dataA & x, dataB & x\n",
    "        while dataB != 0:\n",
    "            dataA, dataB = (dataA ^ dataB), (dataA & dataB) << 1 & x\n",
    "        return dataA if dataA <= 0x7fffffff else ~(dataA ^ x)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        x = 0xffffffff\n",
    "        dataA, dataB = dataA & x, dataB & x\n",
    "        while dataB != 0:\n",
    "            dataA, dataB = (dataA ^ dataB), (dataA & dataB) << 1 & x\n",
    "        return dataA if dataA <= 0x7fffffff else ~(dataA ^ x)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        return dataA+dataB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        #获取负数的补码： 需要将数字与十六进制数 0xffffffff 相与。\n",
    "        #可理解为舍去此数字 32 位以上的数字（将 32 位以上都变为 000 ），\n",
    "        #从无限长度变为一个 32 位整数。\n",
    "        x=0xffffffff\n",
    "        dataA &= x\n",
    "        dataB &= x\n",
    "        while dataB!=0: # 直到进位为0\n",
    "            temp = ((dataA&dataB)<<1)&x  # 进位：与运算 + 左移一位\n",
    "            dataA^=dataB   # 本位：异或运算\n",
    "            dataB=temp \n",
    "        if dataA <= 0x7fffffff: #0x7fffffff 是最大的正数的补码。\n",
    "        # 当你尝试将 0x7fffffff 加 1 时，会发生溢出，结果将变为负数，即 -2147483648\n",
    "            return dataA\n",
    "        else:\n",
    "            return ~(dataA^x)  #计算整数 a 的相反数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        x = 0xffffffff\n",
    "        dataA, dataB = dataA & x, dataB & x\n",
    "        while dataB != 0:\n",
    "            dataA, dataB = (dataA ^ dataB), (dataA & dataB) << 1 & x\n",
    "        return dataA if dataA <= 0x7fffffff else ~(dataA ^ x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        return dataA + dataB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        x = 0xffffffff\n",
    "        dataA,dataB = dataA&x,dataB&x\n",
    "        while dataB !=0:\n",
    "            dataA,dataB = (dataA^dataB),(dataA&dataB)<<1 &x\n",
    "        return dataA if dataA<=0x7fffffff else ~(dataA^x)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        x = 0xffffffff\n",
    "        dataA, dataB = dataA & x, dataB & x\n",
    "        while dataB != 0:\n",
    "            dataA, dataB = (dataA ^ dataB), (dataA & dataB) << 1 & x\n",
    "        return dataA if dataA <= 0x7fffffff else ~(dataA ^ x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        return dataA + dataB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        x = 0xffffffff\n",
    "        dataA, dataB = dataA & x, dataB & x\n",
    "        while dataB != 0:\n",
    "            dataA, dataB = (dataA ^ dataB), (dataA & dataB) << 1 & x\n",
    "        return dataA if dataA <= 0x7fffffff else ~(dataA ^ x)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        MX = 0xffffffff\n",
    "        dataA, dataB = dataA & MX, dataB & MX\n",
    "        while dataB != 0:\n",
    "            dataA, dataB = (dataA ^ dataB), (dataA & dataB) << 1 & MX\n",
    "        return dataA if dataA <= 0x7fffffff else ~(dataA ^ MX)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        return dataA + dataB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        return dataA+dataB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        x = 0xffffffff\n",
    "        dataA, dataB = dataA & x, dataB & x\n",
    "        while dataB != 0:\n",
    "            dataA, dataB = (dataA ^ dataB), (dataA & dataB) << 1 & x\n",
    "        return dataA if dataA <= 0x7fffffff else ~(dataA ^ x)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        x = 0xffffffff\n",
    "        dataA, dataB = dataA & x, dataB & x\n",
    "        while dataB != 0:\n",
    "            dataA, dataB = (dataA ^ dataB), (dataA & dataB) << 1 & x\n",
    "        return dataA if dataA <= 0x7fffffff else ~(dataA^x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        a, b = dataA, dataB\n",
    "        x = 0xffffffff\n",
    "        a, b = a & x, b & x\n",
    "        while b != 0:\n",
    "            a, b = (a ^ b), (a & b) << 1 & x\n",
    "        return a if a <= 0x7fffffff else ~(a ^ x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def encryptionCalculate(self, dataA: int, dataB: int) -> int:\n",
    "        return dataA + dataB"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
